Interop Forms Toolkit
Interop User Control Events

Interop UserControls provide a basic set of intrinsic events (Click, GotFocus, Validate, etc.) in Visual Basic 6.0. You can define your own custom events in Visual Studio .NET and raise them using RaiseEvent. In order to handle the events in Visual Basic 6.0, you need to add a project reference and add a WithEvents variable declaration in your code, and then handle the events using the WithEvents variable rather than the control itself.

How To Handle Interop UserControl Custom Events

  1. In Visual Basic 6.0, on the Project menu, click References. Note that there is already a reference to ControlNameCtl, where ControlName is the name of your Interop UserControl.

  2. In the Available References list, locate a reference for ControlName and check it, and then click OK.

  3. In the Code Editor, add a declaration for a WithEvents variable: 

    Dim WithEvents ControlNameEvents As ControlLibrary.ControlName
                    

In the Form_Load event handler, add the following code to initialize the WithEvents variable:

Private Sub Form_Load()
Set ControlNameEvents = Me.ControlNameOnVB6Form
End Sub

Add code to handle your custom event in the WithEvents variable's event handler:

Private Sub ControlNameEvents_MyCustomEvent()
MsgBox("My custom event fired")
End Sub